{{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}Decoder : Json.Decode.Decoder {{classname}}
{{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}Decoder ={{^discriminator}}
    Json.Decode.oneOf{{#oneOf}}
        {{#-first}}[{{/-first}}{{^-first}},{{/-first}} Json.Decode.map {{classname}}{{{.}}} {{#lambda.camelcase}}{{{.}}}{{/lambda.camelcase}}Decoder{{/oneOf}}
        ]
{{/discriminator}}{{#discriminator}}
    Json.Decode.field "{{{propertyName}}}" Json.Decode.string
        |> Json.Decode.andThen {{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}TagDecoder


{{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}TagDecoder : String -> Json.Decode.Decoder {{classname}}
{{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}TagDecoder tag =
    case tag of
{{#mappedModels}}
        "{{mappingName}}" ->
            Json.Decode.map {{classname}}{{modelName}} {{#lambda.camelcase}}{{modelName}}{{/lambda.camelcase}}Decoder

{{/mappedModels}}
        _ ->
            Json.Decode.fail <| "Trying to decode {{classname}}, but {{{propertyName}}} '" ++ tag ++ "' is not supported."
{{/discriminator}}